using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class BillDetailMap : EntityTypeConfiguration<BillDetail>
    {
        public BillDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            // Table & Column Mappings
            this.ToTable("BillDetails");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.BillOutID).HasColumnName("BillOutID");
            this.Property(t => t.PurchaseDetailID).HasColumnName("PurchaseDetailID");
            this.Property(t => t.MaterialID).HasColumnName("MaterialID");
            this.Property(t => t.UOMID).HasColumnName("UOMID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Price_In).HasColumnName("Price_In");
            this.Property(t => t.Maintenancecost).HasColumnName("Maintenancecost");
            this.Property(t => t.Price_Out).HasColumnName("Price_Out");
            this.Property(t => t.TotalMoney).HasColumnName("TotalMoney");

            // Relationships
            this.HasRequired(t => t.BillOut)
                .WithMany(t => t.BillDetails)
                .HasForeignKey(d => d.BillOutID);
            this.HasOptional(t => t.Material)
                .WithMany(t => t.BillDetails)
                .HasForeignKey(d => d.MaterialID);
            this.HasOptional(t => t.PurchaseDetail)
                .WithMany(t => t.BillDetails)
                .HasForeignKey(d => d.PurchaseDetailID);
            this.HasOptional(t => t.UOM)
                .WithMany(t => t.BillDetails)
                .HasForeignKey(d => d.UOMID);

        }
    }
}
